package com.At;

import java.util.HashMap;
import java.util.Map;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;



import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.Sv.testSv;
import com.ibatis.common.resources.Resources;


public class accessAction extends SetupAt {
	

	private static Logger Log = Logger.getLogger(testAction.class);
	public static testSv tsv = testSv.getInstance();
	
	
	
	public String joinUs(){
				
		
		Map<String, Object> param = getParameterNameAndValueMap();
		Map<String, Object> result = new HashMap<String, Object>();
		
		System.out.println(param.toString());
		
		System.out.println("@@@@"+param.toString());
		
/*		result = tsv.getInsert(param);*/
		
		
		
		
		return SUCCESS;
	}
	
	public String idcheck() throws IOException{
		
		
		PrintWriter out = res.getWriter();
		Map<String,Object> param = getParameterNameAndValueMap();
		Map<String,Object> result = new HashMap<String,Object>();
			
		
		param.put("uid",utill.replace(param.get("uid")));
		

		result = tsv.getMinfo(param);
		
		System.out.println("ss"+param.get("uid"));
		out.println(result.get("check"));
	    out.flush();
	    out.close();
	
		
		return SUCCESS;
	}
	public String zipcode() throws IOException{
		
	
		Map<String,Object> param = getParameterNameAndValueMap();
		Map<String,Object> result = new HashMap<String,Object>();
		
	//String var = new String(trim(getName()).getBytes("8859_1"),"UTF-8");
		if(param.get("search") !=null ){

			
		
			param.put("search",utill.replace(param.get("search")));
			
			
			System.out.println("ok?");
			result = tsv.getZipcode(param);
		
		}
			
		req.setAttribute("result",result);
			
			return SUCCESS;
	
	}
	public String joinOk() throws IOException{
		
		Map<String,Object> param = getParameterNameAndValueMap();
		Map<String,Object> result = new HashMap<String,Object>();
		
		
		
		result = tsv.insertMember(param);
		
		return SUCCESS;
		
	}
	public String login() throws IOException{
		
		PrintWriter out = res.getWriter();
		Map<String,Object> param = getParameterNameAndValueMap();
		Map<String,Object> result = new HashMap<String,Object>();
		HttpSession session = req.getSession();
		
				
		result = tsv.LoginCheck(param);
		System.out.println("result:"+result.get("pwd"));
		System.out.println("param:"+param.get("pwd"));
		
		// 로그인 result 값 // 
		if(result.get("count").equals("0")){
			out.println("0");
		}else if(result.get("count").equals("1") && result.get("pwd").equals(param.get("pwd"))){
			session.setAttribute("logid",param.get("uid"));
			session.setAttribute("name",result.get("name"));
			session.setMaxInactiveInterval(60*10);
			//#################################################//
			Log.info("로그인아이디:"+param.get("uid"));
			Log.info(param.get("uid")+"의 이름:"+result.get("name"));
			//#################################################//
			out.println("1");
		}else{
			out.println("2");
		}
	
		//end// 
		
		out.close();
		req.setAttribute("result",result);
			
			return SUCCESS;
	
	}

	
}



